<?php // $Id: mysql.php,v 1.21.2.1 2005/05/31 23:02:44 moodler Exp $

//PAJA modify 21.4.2006 17:01:44
function aca_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality

    global $CFG;

    if ($oldversion < 2006040100) {

        execute_sql("
        CREATE TABLE `prefix_aca` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `course` int(10) unsigned NOT NULL default '0',
          `name` varchar(255) NOT NULL default '',
          `description` text NOT NULL,
          `format` tinyint(4) unsigned NOT NULL default '0',
          `langtype` varchar(50) NOT NULL default '',
          `resubmit` tinyint(2) unsigned NOT NULL default '0',
          `preventlate` tinyint(2) unsigned NOT NULL default '0',
          `emailteachers` tinyint(2) unsigned NOT NULL default '0',
          `maxbytes` int(10) unsigned NOT NULL default '100000',
          `timedue` int(10) unsigned NOT NULL default '0',
          `timeavailable` int(10) unsigned NOT NULL default '0',
          `grade` int(10) NOT NULL default '0',
          `gradetype` tinyint(4) unsigned NOT NULL default '0',
          `grademax` tinyint(4) unsigned NOT NULL default '0',
          `grademin` tinyint(4) unsigned NOT NULL default '0',
          `graderandval` int(10) default '0',
          `showtest` tinyint(2) unsigned NOT NULL default '0',
          `showcopy` tinyint(2) unsigned NOT NULL default '0',
          `sourcefile` varchar(255) NOT NULL default '',
          `timemodified` int(10) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`),
          KEY `course` (`course`)
        ) TYPE=MyISAM COMMENT='Defines aca module'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_pd_active` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `pdid` int(10) unsigned NOT NULL default '0',
          `acaid` int(10) unsigned NOT NULL default '0',
          `border` int(11) NOT NULL default '0',
          `false_opt` tinyint(4) unsigned NOT NULL default '0',
          `false_val` int(11) NOT NULL default '0',
          `test_opt` tinyint(4) unsigned NOT NULL default '0',
          `test_val` varchar(100) NOT NULL default '',
          `timemodified` int(10) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`),
          KEY `acaid` (`acaid`),
          KEY `pdid` (`pdid`)
        ) TYPE=MyISAM COMMENT='Table of active plagiat detectors'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_pd_similarity` (
          `id` int(10) NOT NULL auto_increment,
          `id_pri` int(10) unsigned NOT NULL default '0',
          `id_sec` int(10) unsigned NOT NULL default '0',
          `similarity` float NOT NULL default '0',
          `acaid` int(10) unsigned NOT NULL default '0',
          `activepdid` int(10) NOT NULL default '0',
          PRIMARY KEY  (`id`)
        ) TYPE=MyISAM COMMENT='Info about similarities between submissions'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_pds` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `langtype` varchar(50) NOT NULL default '',
          `name` varchar(255) NOT NULL default '',
          `timemodified` int(10) unsigned NOT NULL default '0',
          `resultmax` int(11) NOT NULL default '0',
          `resultmin` int(11) NOT NULL default '0',
          `resultdefault` int(11) NOT NULL default '0',
          PRIMARY KEY  (`id`)
        ) TYPE=MyISAM COMMENT='Table of all usable aca plagiat detectors'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_submissions` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `acaid` int(10) unsigned NOT NULL default '0',
          `userid` int(10) unsigned NOT NULL default '0',
          `timecreated` int(10) unsigned NOT NULL default '0',
          `timemodified` int(10) unsigned NOT NULL default '0',
          `numfiles` int(10) unsigned NOT NULL default '0',
          `grade` int(11) NOT NULL default '0',
          `comment` text NOT NULL,
          `format` tinyint(4) unsigned NOT NULL default '0',
          `teacher` int(10) unsigned NOT NULL default '0',
          `timemarked` int(10) unsigned NOT NULL default '0',
          `mailed` tinyint(1) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`),
          KEY `acaid` (`acaid`),
          KEY `userid` (`userid`),
          KEY `mailed` (`mailed`),
          KEY `timemarked` (`timemarked`)
        ) TYPE=MyISAM COMMENT='Info about submitted ac assignments'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_tv_active` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `tvid` int(10) unsigned NOT NULL default '0',
          `acaid` int(10) unsigned NOT NULL default '0',
          `test_opt` tinyint(4) unsigned NOT NULL default '0',
          `test_val` varchar(255) NOT NULL default '',
          `in_opt` tinyint(4) unsigned NOT NULL default '0',
          `in_string` varchar(255) NOT NULL default '',
          `in_text` text NOT NULL,
          `grade` int(11) NOT NULL default '0',
          `timemodified` int(10) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`),
          KEY `tvid` (`tvid`),
          KEY `acaid` (`acaid`)
        ) TYPE=MyISAM COMMENT='Table of active test vectors'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_tv_results` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `activetvid` int(10) unsigned NOT NULL default '0',
          `acaid` int(10) unsigned NOT NULL default '0',
          `submissionid` int(10) unsigned NOT NULL default '0',
          `indata` text NOT NULL,
          `teacher_out` text NOT NULL,
          `student_out` text NOT NULL,
          `result` tinyint(2) unsigned NOT NULL default '0',
          `description` text NOT NULL,
          `timemodified` int(10) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`),
          KEY `tvid` (`activetvid`),
          KEY `acaid` (`acaid`),
          KEY `submissionid` (`submissionid`)
        ) TYPE=MyISAM COMMENT='Test vector results for each submission'
        ");
        
        execute_sql("
        CREATE TABLE `prefix_aca_tvs` (
          `id` int(10) unsigned NOT NULL auto_increment,
          `langtype` varchar(50) NOT NULL default '',
          `name` varchar(255) NOT NULL default '',
          `timemodified` int(10) unsigned NOT NULL default '0',
          PRIMARY KEY  (`id`)
        ) TYPE=MyISAM COMMENT='Table of all usable aca test vectors'
        ");
	}
    
    /*
    if ($oldversion < 2005060100) {
        include_once("$CFG->dirroot/mod/assignment/lib.php");
        // PAJA modify 21.4.2006 17:01:59
        aca_refresh_events();
    }
    */


/// These lines ALWAYS need to be here at the end of this file.  Don't mess with them. :-)
    //PAJA modify 21.4.2006 17:02:43
    include_once("$CFG->dirroot/mod/aca/lib.php");
    //PAJA modify 21.4.2006 17:02:13
    // upgrade some submodules (same module structure as this module - version.php, dir db, ...)
    aca_upgrade_submodules();

    return true;
}

?>
